package org.xlx.xlx_oa.common;

import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;

public interface BaseConvertor {
    default LocalDate mapLongToLocalDate(Long timestamp) {
        return (timestamp == null || timestamp == 0) ? null :
                LocalDate.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
    }

    default LocalDateTime mapLongToLocalDateTime(Long timestamp) {
        return (timestamp == null || timestamp == 0) ? null :
                LocalDateTime.ofInstant(Instant.ofEpochMilli(timestamp), ZoneId.systemDefault());
    }

    default Long mapLocalDateToLong(LocalDate localDate) {
        return localDate == null ? 0 : localDate.atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
    }

    default Long mapLocalDateTimeToLong(LocalDateTime localDateTime) {
        Long result = localDateTime == null ? 0 :
                localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
        return result;
    }
}
